<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
   <title>皇室蛋糕</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" type="image/x-icon" href="resource/bifavi.ico" rel="external nofollow" /> 
    <link rel="stylesheet" href="lib/layui/css/layui.css">
    <link rel="stylesheet" href="css/scroll-bar.css">
    <link rel="stylesheet" href="css/sub-page.css">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_wytlyqhtdtj1nhfr.css">
    <link rel="stylesheet" href="lib/nprogress/nprogress.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>常用页面</cite></a>
                <a><cite>文章列表</cite></a>
            </span>
        <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form layui-col-md12 ok-search" method="post">
            <input class="layui-input" placeholder="请输入产品名字" autocomplete="off" id="cakename">
            <button class="layui-btn" lay-submit="" lay-filter="search" id="search" type="button">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </form>
    </div>
    <!--工具栏-->
    <okToolbar>
        <!-- <button class="layui-btn layui-btn-normal" id="batchEnabled">
            <i class="iconfont icon-shangsheng"></i>批量上架
        </button>
        <button class="layui-btn layui-btn-warm" id="batchDisabled">
            <i class="iconfont icon-web-icon-"></i>批量下架
        </button>
        <button class="layui-btn layui-btn-danger" id="batchDel">
            <i class="layui-icon layui-icon-delete"></i>批量删除
        </button> -->
        <button class="layui-btn" id="addUser">
            <i class="layui-icon">&#xe61f;</i>添加产品
        </button>
        <button class="layui-btn" id="addUser">
            <a href="index.jsp">跳回商城主页</a>
        </button>
        <span>共有数据：<i id="countNum"></i> 条</span>
    </okToolbar>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<div   style="display: none;" id="editCake">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>常用页面</cite></a>
                <a><cite>产品列表</cite></a>
				<a><cite>编辑产品</cite></a>
            </span>
        <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh">刷新</i>刷新
        </a>
    </div>
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form" id="editCakeSerialize">
    <input type="hidden" name="cakeId" id="cakeId">
        <div class="layui-form-item">
            <label class="layui-form-label">产品名称</label>
            <div class="layui-input-block">
                <input type="text" name="cakeName" id="cakeName" placeholder="请输入成品名字" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型分类</label>
            <div class="layui-input-block">
                <select name="caketypeId" id="caketypeId">
                    <option value="0">蛋糕</option>
                    <option value="1">吐司</option>
                    <option value="2">礼品</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单价</label>
            <div class="layui-input-block">
                <input type="text" name="cakePrice" id="cakePrice" placeholder="请输入产品单价" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <textarea name="cakeContext" id="cakeContext" placeholder="请输入产品介绍内容" class="layui-textarea" lay-verify="required"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="editCakeSub">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="lib/layui/layui.js"></script>
<script src="lib/nprogress/nprogress.js"></script>
<script>
    // 进度条加载提示
    NProgress.start();
    window.onload = function () {
        NProgress.done();
    }
    // layui相关
    layui.use(['element', 'table', 'form', 'jquery', 'laydate'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#startTime',
            type: "datetime"
        });

        laydate.render({
            elem: '#endTime',
            type: "datetime"
        });

        table.render({
            elem: '#tableId',
            url: 'getCakeAdmins',
            limit: 10,
            page: true,
            even: true,
            cols: [[
                {type: 'checkbox'},
                {field: 'id', title: 'ID', width: 80, sort: true},
                {field: 'cakename', title: '产品名称', width: 300},
                {field: 'cakecontext', title: '产品介绍', width: 350},
              /*   {field: 'cakeupprice', title: '价', width: 250, templet: '#urlTpl'}, */
                {field: 'cakeprice', title: '单价', width: 150},
                {field: 'cakesales', title: '售量', width: 150},
                {field: 'type', title: '产品类型', width: 200},
                /* {field: 'isTop', title: '置顶', width: 100, templet: '#topTpl'}, */
                {title: '编辑修改', width: 200, templet: '#operationTpl', align: 'center'}
            ]],
            done: function (res, curr, count) {
                $("#countNum").text(count);
            }
        });
		/*
		模糊查询
		*/
		$("#search").click(function() {
			//alert("sdafasfa");
        //form.on('submit(search)', function () {
        	var name=$("#cakename").val();
            layer.msg('正在查询，请稍后...');
            	console.log(name);
	            table.render({
	                elem: '#tableId',
	                url: 'findCakeLikeName',
	                limit: 10,
	                page: true,
	                even: true,
	                where :{
	                	cakename: name
	                },
	                cols: [[
	                    {type: 'checkbox'},
	                    {field: 'id', title: 'ID', width: 80, sort: true},
	                    {field: 'cakename', title: '产品名称', width:250},
	                    {field: 'cakecontext', title: '产品介绍', width: 350},
	                  /*   {field: 'cakeupprice', title: '价', width: 250, templet: '#urlTpl'}, */
	                    {field: 'cakeprice', title: '单价', width: 80},
	                    {field: 'cakesales', title: '售量', width: 80},
	                    {field: 'type', title: '产品类型', width: 300},
	                    /* {field: 'isTop', title: '置顶', width: 100, templet: '#topTpl'}, */
	                    {title: '操作', width: 200, templet: '#operationTpl', align: 'center'}
	                ]],
	                done: function (res, curr, count) {
	                    $("#countNum").text(count);
	                }
	            });
            //return false;
        });

        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') {
                layer.open({
                    title: '编辑用户',
                    type: 1,
                    shade: false,
                    maxmin: true,
                    shade: 0.5,
                    area: ['90%', '90%'],
                    content:  $('#editCake'),
                    zIndex: layer.zIndex,
                    end: function () {
                        $(".layui-laypage-btn")[0].click();
                    }
                });
                console.log(data);
                $("#cakeId").val(data.id);
                $("#cakeName").val(data.cakename);
                $("#cakeContext").val(data.cakecontext);
                $("#cakePrice").val(data.cakeprice);
                var ty=data.type;
                if (ty=="蛋糕") {
                	//alert("蛋糕");
                	$("#caketypeId").val(0);
				} else if(ty =="吐司"){
					//alert("吐司");
					$("#caketypeId").val(1);
					
				}else if(ty == "礼品"){
					//alert("礼品");
					$("#caketypeId").val(2);
				}
                layui.form.render('select');
            } else if (layEvent === 'del') {
                layer.confirm("确定要删除吗？", {skin: 'layui-layer-lan', icon: 2, title: '提示', anim: 6}, function () {
                    layer.msg("操作成功！", {icon: 1, time: 1000});
                });
            }
        });
		// 编辑商品
        form.on('submit(editCakeSub)', function (data) {
            console.log(data.field);
            var ser=$("#editCakeSerialize").serialize();
            console.log(ser);
	        $.post("editCake?ser="+ser,function(result){
    			//document.getElementById("txtHint").innerHTML = result;
            	 console.log(result+"@@@@@@@@@@@@@@@@@@");
            	
    		},"JSON");  
            layer.msg("编辑成功！", {icon: 6, time: 1000, anim: 4}, function () {
            	 window.location.href="adminCake.jsp";
            }); 
            return false;
        });
        


        $("#addUser").click(function () {
            layer.open({
                title: '添加文章',
                type: 2,
                shade: false,
                maxmin: true,
                shade: 0.5,
                anim: 4,
                area: ['90%', '90%'],
                content: 'AdminCakeAdd.jsp',
                zIndex: layer.zIndex,
                // skin: 'layui-layer-molv',
                end: function () {
                    $(".layui-laypage-btn")[0].click();
                }
            });
        })
    })
</script>
<!--模板-->
<script type="text/html" id="urlTpl">
    <a href="{{d.url}}" target="_blank">{{d.url}}</a>
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:;" title="编辑" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
</script>
</body>
</html>